#include<bits/stdc++.h>
using namespace std;
#define gc getchar
#define pc putchar
#define pb push_back
#define mp make_pair
#define ls (id<<1)
#define rs ((id<<1)|1)
#define mid ((l+r)>>1)
#define int long long
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)

int read(){
    int ret=0,f=0; char ch=gc();
    while(ch<'0'||ch>'9') f|=(ch=='-'),ch=gc();
    while(ch>='0'&&ch<='9') ret=(ret<<1)+(ret<<3)+(ch^48),ch=gc();
    return f?-ret:ret;
}

void write(int x){
    if(!x) return pc('0'),void();
    if(x<0) pc('-'),x=-x;
    int stk[30],tp=0;
    while(x) stk[++tp]=x%10,x/=10;
    while(tp) pc('0'+stk[tp--]);
    return;
}

const int Maxn=1e6+10;
int N,K,A[Maxn],l,r,Ans,Num[Maxn];

bool check(int p,bool lim1,bool lim2){
    if(!p||(!lim1&&!lim2)) return 1;
    int tl=lim1?(p==1?1:0):0,tr=lim2?A[p]:K-1;
    For(i,tl,tr){
        if(!Num[i]) continue;
        --Num[i];
        bool f=check(p-1,lim1&(p==1?i==1:!i),lim2&(A[p]==i));
        ++Num[i];
        if(f) return 1;
    }
    return 0;
}

void DFS(int x,int v){
    if(x==K-1){
        Num[x]=v;
        if(check(N,1,1)) ++Ans;
        return;
    }
    For(i,0,v) Num[x]=i,DFS(x+1,v-i);
}

signed main(){
    freopen("count.in","r",stdin);
    freopen("count.out","w",stdout);
    N=read(),K=read(); Rof(i,N,1) A[i]=read();
    DFS(0,N); write(Ans);
    return 0;
}